﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using Utils;
using ModbusTest.Config;

namespace ModbusTest
{
     
    public class GasPressureTester
    {
        SerialPortUtil serialUtil;
        SerialPort _port;
        float TestValue;
        ModuleConfig _cfg;
        public GasPressureTester(SerialPort port,ModuleConfig cfg)
        {
            serialUtil = new SerialPortUtil(port);
            _cfg = cfg;
            _port = port;
            serialUtil.DataReceived += serialUtil_DataReceived;
        }

        void serialUtil_DataReceived(DataReceivedEventArgs e)
        {
                string date = e.DataReceived;
                Console.WriteLine("空气量仪数据："+date);
                StreamWriter sw = new StreamWriter("kqly.txt",true);
                sw.WriteLine(date);
                sw.Flush();
                sw.Close();
                float.TryParse(date.Substring(5, 8), out TestValue);
                var s = from a in _cfg.Specifications where a.Description == "轴承孔直径" select a;
                foreach (var b in s)
                {
                    b.TestValue = TestValue;
                }
                Console.WriteLine("解析后数据：{0}",TestValue);
        }
    }
}
